let startButton = document.getElementById('startButton');
startButton.onclick = function(element) {
    if(startButton.className){//防连点
        alert('已监控');
        return false;
    }
    var myNickName = document.getElementById('myNickName').value;
    if(!myNickName){
        alert('请输入要监控昵称的关键字');
        return false;
    }
    // setStorage('myNickName',myNickName);
    chrome.tabs.query({active: true, currentWindow: true},function(tabs){
        chrome.tabs.sendMessage(tabs[0].id,{danmuTask: "startObserve",myNickName:myNickName}, function(response) {
            console.log(response);
            startButton.className = 'startCheck';
            endButton.className = '';
        });
    });
};

let endButton = document.getElementById('endButton');
endButton.onclick = function(element){
    if(endButton.className){
        alert('已撤销');
        return false;
    }
    var myNickName = document.getElementById('myNickName').value;
    if(!myNickName){
        alert('请输入要监控昵称的关键字');
        return false;
    }
    chrome.tabs.query({active: true, currentWindow: true},function(tabs){
        chrome.tabs.sendMessage(tabs[0].id,{danmuTask: "stopObserve",myNickName:myNickName}, function(response) {
            console.log(response);
            startButton.className = '';
            endButton.className = 'startCheck';
        });
    });  
}

function setStorage(skey,sValue){
    chrome.storage.sync.set({skey:sValue}, function() {
        console.log('%s set %s', skey,sValue);
    });
}